<%--
  Created by IntelliJ IDEA.
  User: 31036
  Date: 2025/3/25
  Time: 20:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <script src="../../static/js/jquery-1.8.3.js"></script>
    <link href="../../static/layui/css/layui.css" rel="stylesheet">
    <script>
        $(function () {
            getPark()
        })

        //动态下拉
        function getPark() {
            $.ajax({
                url: "/park/getParkList",
                dataType: "json",
                success(res) {
                    $("#parkId").empty()
                    $("#parkId").append(`
                         <option value="">请选择</option>
                    `)
                    for (let x of res) {
                        $("#parkId").append(`
                         <option value="\${x.parkId}">\${x.parkName}</option>
                    `)

                    }
                }

            })
        }
    </script>
</head>
<body>
停车场: <select id="parkId">
    <option value="">请选择</option>
</select><br>
车牌号: <input type="text" id="carCard"><br>
车辆类型: <select id="carType">
    <option value="">请选择</option>
    <option value="0">小型车</option>
    <option value="1">大型车</option>
</select><br>
<div class="layui-inline">
    <label class="layui-form-label">开始时间</label>
    <div class="layui-input-inline layui-input-wrap">
        <div class="layui-input-prefix">
            <i class="layui-icon layui-icon-date"></i>
        </div>
        <input type="text" name="date" id="startTime" lay-verify="date" placeholder="yyyy-MM-dd HH:mm:ss"
               autocomplete="off"
               class="layui-input">
    </div>
</div>
<div class="layui-inline">
    <label class="layui-form-label">结束时间</label>
    <div class="layui-input-inline layui-input-wrap">
        <div class="layui-input-prefix">
            <i class="layui-icon layui-icon-date"></i>
        </div>
        <input type="text" name="date" id="endTime" lay-verify="date" placeholder="yyyy-MM-dd HH:mm:ss"
               autocomplete="off"
               class="layui-input">
    </div>
</div>
<br>

支付方式: <select id="rechargeType">
    <option value="">请选择</option>
</select><br>
<input type="button" value="确定" onclick="addOrderPark()">
<input type="button" value="取消" onclick="history.back()">
<script src="../../static/layui/layui.js"></script>
<script>
    layui.use(['form', 'laydate', 'util'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        $.ajaxSettings.async=false;
        $.ajax({
            url: "/dian/getRechargeType",
            dataType: "json",
            success(res) {
                $("#rechargeType").empty()
                $("#rechargeType").append(`
                    <option value="">请选择</option>
                `)
                for (let x of res) {
                    $("#rechargeType").append(`
                    <option value="\${x.dianName}">\${x.dianValue}</option>
                `)
                }
            }

        })
        form.render();


        // 日期
        laydate.render({
            elem: '#startTime',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss'
        });
        // 日期
        laydate.render({
            elem: '#endTime',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss'
        });

    });


</script>


</body>
<script>
    function addOrderPark() {
        let parkId = $("#parkId").val();
        let carCard = $("#carCard").val();
        let carType = $("#carType").val();
        let startTime = $("#startTime").val();
        let endTime = $("#endTime").val();
        let rechargeType = $("#rechargeType").val();
        let obj = {parkId, carCard, carType, startTime, endTime, rechargeType}

        $.ajax({
            url: "/orderPark/addOrderPark",
            type: "post",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(obj),
            dataType: "json",
            success(res) {
                if (res.code === 200) {
                    alert("新增成功")
                    location.href = "";
                }
                if (res.code === 100) {
                    alert(res.msg)
                }
            },
            error() {
                alert("服务器错误")
            }

        })
    }
</script>
</html>
